#testing yatsy API

__author__ = 'cephire@google.com (Joseph Jude)'

import urllib
import urllib2
import base64

url = 'http://localhost:8000/init/api/assign/'
username = 'agent1@example.com'
password = 'web2py'
USER_AGENT = 'TestServer'

request = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % (username,password))
authheader =  "Basic %s" % base64string
request.add_header('USER_AGENT', USER_AGENT)
request.add_header('AUTHORIZATION', authheader)


data = {
		'fields': {'case_id': 16, 'assign_to': 'agent1@example.com'}
		}

data = dict(case_id=16, assign_to='agent1@example.com')
data = '%s=%s' % ('fields', data)
#data = urllib.urlencode(data)
print data
try:
  response = urllib2.urlopen(request,data).read()
  print "response is: %s" % response
except urllib2.HTTPError, e:
  print e.code
  print e.read()
except urllib2.URLError, e:
   if hasattr(e, 'reason'):
    print e.reason
   elif hasattr(e,'code'):
    print e.code